package com.cloudsea.gateway.filter.global;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.HandlerStrategies;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@Component
public class LogGlobalFilter implements GlobalFilter {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        System.out.println("进来了");
        ServerRequest serverRequest = ServerRequest.create(exchange.mutate().request(exchange.getRequest()).build(), HandlerStrategies.withDefaults().messageReaders());
        serverRequest.bodyToMono(String.class).subscribe(System.out::println);
        return chain.filter(exchange);
    }
}
